﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace CompareIt.Engine.Entities
{
    public class TableSchema : ITableSchema
    {
        private List<string> m_DirtyProperties = null;
        private string m_Name = null;
        private DateTime m_CreationDate = DateTime.MinValue;

        #region ITableSchema Members

        /// <summary>
        /// Gets the table name.
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; MarkDirty("Name"); }
        }

        /// <summary>
        /// Gets or sets the table creation date.
        /// </summary>
        public DateTime CreationDate
        {
            get { return m_CreationDate; }
            set { m_CreationDate = value; MarkDirty("CreationDate"); }
        }

        #endregion

        protected List<string> DirtyProperties
        {
            get { return m_DirtyProperties; }
        }

        public TableSchema()
        {
            m_DirtyProperties = new List<string>();
        }


        #region IEquatable<ITableSchema> Members

        public virtual bool Equals(ITableSchema other)
        {
            bool isEqual = true;
            bool isNameEqual = Name.Equals(other.Name, StringComparison.InvariantCulture);
            Debug.Assert(isNameEqual, "The table name is not equal!");
            if (!isNameEqual)
            {
                isEqual = isEqual && false;
            }
            return isEqual;
        }

        #endregion

        /// <summary>
        /// Mark a property has dirty.
        /// </summary>
        /// <param name="propertyName">The name of the property that is dirty.</param>
        protected virtual void MarkDirty(string propertyName)
        {
            if (!DirtyProperties.Contains(propertyName))
            {
                DirtyProperties.Add(propertyName);
            }
        }
    }
}
